package org.aurora.one.noticeAndWait_2;

import org.aurora.myQueue.MyBlockingQueue;
import org.aurora.one.threeMethod_1.RunnableMethod;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

import static org.aurora.myQueue.MyBlockingQueue.blockingQueue;

/**
 * @author : Aurora
 * @date : 2024/1/21 22:18
 * @description
 */
@Component
public class ProductExample implements Runnable{


    private Integer count = 1;
    @Override
    public void run(){
       while(true){
           synchronized (blockingQueue){
               while(blockingQueue.size() == 10){
                   try {
                       blockingQueue.wait();
                   } catch (InterruptedException e) {
                       throw new RuntimeException(e);
                   }
               }
               System.out.println("生产了：product"+count);
               blockingQueue.add("product"+count);
               ++count;
               blockingQueue.notifyAll();
           }
       }
    }
}
